/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.pac4.repara;

import edu.uoc.tdp.pac4.beans.Mecanic;
import edu.uoc.tdp.pac4.beans.Peca;
import edu.uoc.tdp.pac4.beans.Reparacio;
import edu.uoc.tdp.pac4.beans.ReparacioMecanic;
import edu.uoc.tdp.pac4.cliente.Principal;
import static edu.uoc.tdp.pac4.cliente.Principal.currentUser;
import edu.uoc.tdp.pac4.comun.Enumerados;
import edu.uoc.tdp.pac4.comun.GestorReparacionesInterface;
import edu.uoc.tdp.pac4.comun.PAC4Exception;
import edu.uoc.tdp.pac4.i18n.TDSLanguageUtils;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author rfebrerg
 */
public class DetalleReparacion extends javax.swing.JInternalFrame {
private ArrayList<Mecanic> mecanics;
private ArrayList<Peca> peces;

private ArrayList<Peca> ComandaPeces;
 private GestorReparacionesInterface conexion;
    
    private final String URL = "localhost";
    private final String JNDI_NAME = "Serv_Reparaciones";
    private final int PORT = 1099;
    private int idReparacion=0;
    private int idMecanicoSelected;
    private ReparacioMecanic reparacio;
    /**
     * Creates new form DetalleReparacion
     */
    public DetalleReparacion(int idRep) throws PAC4Exception {
        this.idReparacion=idRep;
        initComponents();
        conectarServerRMI();
        getInitialData();
    }
 private void getInitialData() throws PAC4Exception {
        getReparacionesById();
        getMecanicos();
        getComanda();
        getPiezas();
        RevisaPermisos();
      
    }
  private void conectarServerRMI() {
        try {
            Registry registry = LocateRegistry.getRegistry(URL, PORT);
            this.conexion = (GestorReparacionesInterface) registry.lookup(JNDI_NAME);
        } catch (NotBoundException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (RemoteException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
  private String extractDate(Date data)
  {
      if(data==null)return "";
      java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("dd/MM/yyyy");
        String fecha = sdf.format(data);
      return fecha;
  }
 private void getReparacionesById() throws PAC4Exception {
        try {

             this.reparacio = conexion.getDetallReparacio(idReparacion);
                CliNomRep.setText(reparacio.getClient().getNom());
                CliNifRep.setText(reparacio.getClient().getNif());
                CliMarcaRep.setText(reparacio.getVehicle().getMarca());
                CliModeRep.setText(reparacio.getVehicle().getModel());
                CliMatrRep.setText(reparacio.getVehicle().getMatricula());
                
                CodRep.setText(Integer.toString(reparacio.getReparacio().getOrdreReparacio()));
                FechaIniRep.setText(extractDate(reparacio.getReparacio().getDataInici()));
                FechaFinRep.setText(extractDate(reparacio.getReparacio().getDataFi()));
                FechaAsignRep.setText(extractDate(reparacio.getReparacio().getDataAssignacio()));
                TiempoRep.setText(Double.toString(reparacio.getReparacio().getComptador()));
                EstadoRep.setText(reparacio.getReparacio().getEstado().trim());
                ObsRep.setText(reparacio.getReparacio().getObservacions());
                idMecanicoSelected=reparacio.getReparacio().getIdMecanic();
               
          
        } catch (RemoteException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 private void getMecanicos() throws PAC4Exception {
          try{
              ComboMecanicos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { TDSLanguageUtils.getMessage("Reparaciones.Seleccionar") }));
           mecanics=conexion.getMecanics();
           int idMecanicselected=-1;
            for (int i = 0; i < mecanics.size(); i++) {
                ComboMecanicos.addItem(mecanics.get(i).getNombre());
                if(mecanics.get(i).getIdMecanic()==idMecanicoSelected)
                {
                    idMecanicselected=i;
                    jLabelMec.setText(mecanics.get(i).getNombre());
                }
            }
            ComboMecanicos.setSelectedIndex(idMecanicselected+1);
       } catch (RemoteException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        }
            
        }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        CliNomRep = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        CliNifRep = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        CliMarcaRep = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        CliModeRep = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        CliMatrRep = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        CodRep = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        EstadoRep = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        FechaIniRep = new javax.swing.JTextField();
        FechaFinRep = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        ObsRep = new javax.swing.JTextArea();
        jBActObservacion = new javax.swing.JButton();
        jPanelMecanico = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        ComboMecanicos = new javax.swing.JComboBox();
        jBAsignarMec = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        FechaAsignRep = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabelMec = new javax.swing.JLabel();
        jLabelMec1 = new javax.swing.JLabel();
        jPanelPiezas = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        PiezasTable = new javax.swing.JTable();
        jBAddPieza = new javax.swing.JButton();
        jBDelPieza = new javax.swing.JButton();
        ComboPiezas = new javax.swing.JComboBox();
        jPanel13 = new javax.swing.JPanel();
        TiempoRep = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        HorasReP = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, TDSLanguageUtils.getMessage("Reparaciones.TtlDatosCliente"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.darkGray));

        jLabel5.setText(TDSLanguageUtils.getMessage("Reparaciones.Nombre"));

        jLabel6.setText(TDSLanguageUtils.getMessage("Reparaciones.Nif"));

        jLabel7.setText(TDSLanguageUtils.getMessage("Reparaciones.Marca"));

        jLabel8.setText(TDSLanguageUtils.getMessage("Reparaciones.Modelo"));

        jLabel10.setText(TDSLanguageUtils.getMessage("Reparaciones.Matricula"));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CliNomRep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CliNifRep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CliMarcaRep, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CliModeRep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CliMatrRep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(CliNomRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(CliNifRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(CliMarcaRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(CliModeRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(CliMatrRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("Reparaciones.TtlReparaciones")));

        jLabel11.setText(TDSLanguageUtils.getMessage("Reparaciones.Id"));

        jLabel12.setText(TDSLanguageUtils.getMessage("Reparaciones.Estado"));

        jLabel1.setText(TDSLanguageUtils.getMessage("Reparaciones.FechaInicio"));

        jLabel3.setText(TDSLanguageUtils.getMessage("Reparaciones.FechaFin"));

        jButton1.setText(TDSLanguageUtils.getMessage("Reparaciones.BtFinalizarRep"));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel11)
                            .addComponent(jLabel3)
                            .addComponent(jLabel12))
                        .addGap(44, 44, 44)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(EstadoRep, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(CodRep, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                                .addComponent(FechaIniRep)
                                .addComponent(FechaFinRep)))))
                .addGap(23, 23, 23))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(CodRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(FechaIniRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(FechaFinRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(EstadoRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("Reparaciones.TtlObs")));

        ObsRep.setColumns(20);
        ObsRep.setRows(5);
        jScrollPane5.setViewportView(ObsRep);

        jBActObservacion.setText(TDSLanguageUtils.getMessage("Reparaciones.BtActualizaObs"));
        jBActObservacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBActObservacionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBActObservacion))
                    .addComponent(jScrollPane5))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBActObservacion))
        );

        jPanelMecanico.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("Reparaciones.Mecanico")));

        ComboMecanicos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        ComboMecanicos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboMecanicosActionPerformed(evt);
            }
        });

        jBAsignarMec.setText(TDSLanguageUtils.getMessage("Reparaciones.BtAsignarMecanico"));
        jBAsignarMec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAsignarMecActionPerformed(evt);
            }
        });

        jLabel22.setText(TDSLanguageUtils.getMessage("Reparaciones.FechaAsig"));

        jLabel23.setText(TDSLanguageUtils.getMessage("Reparaciones.Mecanico"));

        jLabelMec.setText("   ");

        jLabelMec1.setText(TDSLanguageUtils.getMessage("Reparaciones.MecanicoAsig"));

        javax.swing.GroupLayout jPanelMecanicoLayout = new javax.swing.GroupLayout(jPanelMecanico);
        jPanelMecanico.setLayout(jPanelMecanicoLayout);
        jPanelMecanicoLayout.setHorizontalGroup(
            jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                        .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel22)
                            .addComponent(jLabel23))
                        .addGap(29, 29, 29)
                        .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ComboMecanicos, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(FechaAsignRep, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel21))
                    .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                        .addComponent(jBAsignarMec, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelMecanicoLayout.createSequentialGroup()
                        .addComponent(jLabelMec1)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelMec, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanelMecanicoLayout.setVerticalGroup(
            jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(FechaAsignRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addComponent(jLabel21)
                        .addGap(58, 58, 58))
                    .addGroup(jPanelMecanicoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(ComboMecanicos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanelMecanicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelMec)
                            .addComponent(jLabelMec1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBAsignarMec))))
        );

        jPanelPiezas.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("Reparaciones.TtlPiezas")));

        PiezasTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Codigo", "Descripcion", "Cantidad"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(PiezasTable);

        jBAddPieza.setText(TDSLanguageUtils.getMessage("Reparaciones.BtAsignarPieza"));
        jBAddPieza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAddPiezaActionPerformed(evt);
            }
        });

        jBDelPieza.setText(TDSLanguageUtils.getMessage("Reparaciones.BtEliminarPieza"));
        jBDelPieza.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDelPiezaActionPerformed(evt);
            }
        });

        ComboPiezas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        ComboPiezas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboPiezasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelPiezasLayout = new javax.swing.GroupLayout(jPanelPiezas);
        jPanelPiezas.setLayout(jPanelPiezasLayout);
        jPanelPiezasLayout.setHorizontalGroup(
            jPanelPiezasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPiezasLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelPiezasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ComboPiezas, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBAddPieza, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                    .addComponent(jBDelPieza, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(98, 98, 98))
        );
        jPanelPiezasLayout.setVerticalGroup(
            jPanelPiezasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPiezasLayout.createSequentialGroup()
                .addGap(0, 13, Short.MAX_VALUE)
                .addComponent(ComboPiezas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBAddPieza)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBDelPieza))
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("Reparaciones.Tiempo")));

        jLabel13.setText(TDSLanguageUtils.getMessage("Reparaciones.TiempoReparacion"));

        jLabel14.setText(TDSLanguageUtils.getMessage("Reparaciones.Horas"));

        jButton2.setText(TDSLanguageUtils.getMessage("Reparaciones.BtAsignarHoras"));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel13Layout.createSequentialGroup()
                        .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(HorasReP, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TiempoRep, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(TiempoRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(HorasReP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanelPiezas, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(4, 4, 4)
                                .addComponent(jPanelMecanico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 29, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelMecanico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelPiezas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(17, 17, 17))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBActObservacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBActObservacionActionPerformed
Reparacio rep=new Reparacio();
    try {
                rep.setObservacions(ObsRep.getText().trim());
                rep.setOrdreReparacio(idReparacion);
                int resultado=conexion.UpdateObservacionReparacion(rep);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorObservacion"));
            else
            {
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.ObservacionInsertada"),TDSLanguageUtils.getMessage("Reparaciones.ObservacionInsertada"));
                getInitialData();
            }
            
    } catch (PAC4Exception ex) {
        
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    }
        
    }//GEN-LAST:event_jBActObservacionActionPerformed

    private void ComboMecanicosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboMecanicosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ComboMecanicosActionPerformed
private void AsignarMensajero()
{
    
    try {
        int idMecanicselected=0;
            for (int i = 0; i < mecanics.size(); i++) {
                if(mecanics.get(i).getNombre()==ComboMecanicos.getSelectedItem())
                    idMecanicselected=mecanics.get(i).getIdMecanic();
            if(idMecanicselected!=0)
            {
                Reparacio rep=new Reparacio();
                rep.setIdMecanic(idMecanicselected);
                rep.setOrdreReparacio(idReparacion);
                int resultado=conexion.UpdateMecanicoReparacion(rep);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorAsignacionMecanico"));
            else
            {
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.MecanicoAsignado"),TDSLanguageUtils.getMessage("Reparaciones.MecanicoAsignado"));
                getInitialData();
            }
            }
            }
    } catch (PAC4Exception ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    }    
}
    private void jBAsignarMecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAsignarMecActionPerformed
     AsignarMensajero();
    }//GEN-LAST:event_jBAsignarMecActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      FinalizarReparacion();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        AddHorasReparacion();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void ComboPiezasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboPiezasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ComboPiezasActionPerformed

    private void jBAddPiezaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAddPiezaActionPerformed
       int Select=ComboPiezas.getSelectedIndex();
       if(Select>0)
       {
        Peca pe= peces.get(Select-1);
       Reparacio rep=new Reparacio();
    try {

                
                rep.setOrdreReparacio(idReparacion);
                rep.setIdCapTaller(Principal.currentUser.getID());
                int resultado=conexion.AddPecaComanda(rep,pe);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorAsignacionPieza"));
            else
            {
                
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.PiezaAsignado"),TDSLanguageUtils.getMessage("Reparaciones.PiezaAsignado"));
                getComanda();
                
            }
            
            
    } catch (PAC4Exception ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } 
       }
    }//GEN-LAST:event_jBAddPiezaActionPerformed

    private void jBDelPiezaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDelPiezaActionPerformed
       Peca pe= new Peca();
       pe.setCodiPeca(getSelectedPiezasTable());
       Reparacio rep=new Reparacio();
    try {

                
                rep.setOrdreReparacio(idReparacion);
                rep.setIdCapTaller(Principal.currentUser.getID());
                int resultado=conexion.DelPecaComanda(rep,pe);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorEliminarPieza"));
            else
            {
                
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.PiezaEliminada"),TDSLanguageUtils.getMessage("Reparaciones.PiezaEliminada"));
                getComanda();
                
            }
            
            
    } catch (PAC4Exception ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } 
    }//GEN-LAST:event_jBDelPiezaActionPerformed
  private void AddHorasReparacion()
{
    Reparacio rep=new Reparacio();
    try {
        Double horas=Double.parseDouble(HorasReP.getText());
        Double horasTotal=this.reparacio.getReparacio().getComptador();
        if(horas>0)
        {
            
                rep.setComptador(horasTotal+horas);
                rep.setOrdreReparacio(idReparacion);
                int resultado=conexion.UpdateHorasReparacion(rep);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorAsignarHoras"));
            else
            {
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.HorasAsignadas"),TDSLanguageUtils.getMessage("Reparaciones.HorasAsignadas"));
                getInitialData();
            }
        }
            
    } catch (PAC4Exception ex) {
        
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } 
}
       
    private void FinalizarReparacion()
{
   Reparacio rep=new Reparacio();
     try {
                rep.setOrdreReparacio(idReparacion);
                rep.setIdMecanic(reparacio.getReparacio().getIdMecanic());
                int resultado=conexion.FinalizarReparacion(rep);
              if(resultado==0)
                Principal.showError(TDSLanguageUtils.getMessage("Reparaciones.ErrorFinalizarReparacion"));
            else
            {
                Principal.showMessage(TDSLanguageUtils.getMessage("Reparaciones.ReparacionFinalizada"),TDSLanguageUtils.getMessage("Reparaciones.ReparacionFinalizada"));
                getInitialData();
                BloqueaAllBotones();
            }
        
            
    } catch (PAC4Exception ex) {
        
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    }     
}
            
                                                    

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DetalleReparacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DetalleReparacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DetalleReparacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DetalleReparacion.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
              
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CliMarcaRep;
    private javax.swing.JTextField CliMatrRep;
    private javax.swing.JTextField CliModeRep;
    private javax.swing.JTextField CliNifRep;
    private javax.swing.JTextField CliNomRep;
    private javax.swing.JTextField CodRep;
    private javax.swing.JComboBox ComboMecanicos;
    private javax.swing.JComboBox ComboPiezas;
    private javax.swing.JTextField EstadoRep;
    private javax.swing.JTextField FechaAsignRep;
    private javax.swing.JTextField FechaFinRep;
    private javax.swing.JTextField FechaIniRep;
    private javax.swing.JTextField HorasReP;
    private javax.swing.JTextArea ObsRep;
    private javax.swing.JTable PiezasTable;
    private javax.swing.JTextField TiempoRep;
    private javax.swing.JButton jBActObservacion;
    private javax.swing.JButton jBAddPieza;
    private javax.swing.JButton jBAsignarMec;
    private javax.swing.JButton jBDelPieza;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelMec;
    private javax.swing.JLabel jLabelMec1;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanelMecanico;
    private javax.swing.JPanel jPanelPiezas;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    // End of variables declaration//GEN-END:variables

    private void getComanda() {
        Reparacio rep=new Reparacio();
    try {
                DefaultTableModel dtm = new DefaultTableModel(0, 0);
            String header[] = new String[]{
                TDSLanguageUtils.getMessage("Reparaciones.Id"),
                TDSLanguageUtils.getMessage("Reparaciones.Descripcion"), 
                TDSLanguageUtils.getMessage("Reparaciones.PVP")};
            dtm.setColumnIdentifiers(header);
            PiezasTable.setModel(dtm);
                rep.setOrdreReparacio(idReparacion);
                ComandaPeces= conexion.GetComandaPeces(rep);
                for (int i = 0; i < ComandaPeces.size(); i++) {
                Vector<Object> vdata = new Vector<Object>();
                vdata.add(ComandaPeces.get(i).getCodiPeca());
                vdata.add(ComandaPeces.get(i).getDescripcio());
                vdata.add(ComandaPeces.get(i).getPvd());
                             
                dtm.addRow(vdata);
            }
            TableRowSorter sorter = new TableRowSorter(	dtm);
            PiezasTable.setRowSorter(sorter);
            if(ComandaPeces.size()>0) {
                PiezasTable.setRowSelectionInterval(0, 0);
            }
             PiezasTable.repaint();
             dtm.fireTableDataChanged();
             
            
    } catch (PAC4Exception ex) {
        
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (RemoteException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Principal.showError(ex.getMessage());
        Logger.getLogger(DetalleReparacion.class.getName()).log(Level.SEVERE, null, ex);
    }
       
    }
 private int getSelectedPiezasTable()
    {
         int row=PiezasTable.getSelectedRow();
        int idRep=Integer.parseInt(PiezasTable.getValueAt(row, 0).toString());
        return idRep;
    }
    private void getPiezas() throws PAC4Exception {
        try{
              ComboPiezas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { TDSLanguageUtils.getMessage("Reparaciones.Seleccionar") }));
           peces=conexion.getPeces();
           
            for (int i = 0; i < peces.size(); i++) {
                ComboPiezas.addItem(peces.get(i).getDescripcio());
                }
            
       } catch (RemoteException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(GestionReparacionesCapTaller.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void RevisaPermisos() {
        if(currentUser.getPerfil().getId() == Enumerados.PerfilEnum.MECANICO.getPerfil())
        {
            BloqueaBotones();
        }
    }
    
            private void BloqueaAllBotones() {
            BloqueaBotones() ;
            jBActObservacion.setEnabled(false);
            jButton2.setEnabled(false);
            jButton1.setEnabled(false);
            }
private void BloqueaBotones() {
        
            jBAddPieza.setEnabled(false);
            jBDelPieza.setEnabled(false);
            jBAsignarMec.setEnabled(false);
            PiezasTable.setEnabled(false);
        
    }
}
